#ifndef SINGLETONHOLDER_H_
#define SINGLETONHOLDER_H_

#include <boost/thread/mutex.hpp>
#include <string>
#include "Logger.h"

class SingletonHolder
{
	public:
		static Logger& Instance()
		{
			if(myRemoved)
			{
				IsRemoved();
			}
			else
			{
				Build("program");
			}

			return (*myLogger);
		}

		static Logger& Instance(std::string modulName)
		{
			if(myRemoved)
			{
				IsRemoved();
			}
			else
			{
				Build(modulName);
			}

			return (*myLogger);
		}

	private:
		//Data
		static Logger *myLogger;
		static bool myRemoved;
		static boost::mutex myMutex;
		//Functions
		static void Build(std::string modulName)
		{
				if(myLogger == NULL)
				{
					boost::mutex::scoped_lock lock(myMutex);
					if(myLogger == NULL)
					{
						myLogger = new Logger(modulName);
					}
				}

			myRemoved = false;
		}
		
		static void IsRemoved()
		{

		}

		virtual ~SingletonHolder(void)
		{
			delete myLogger;
			myRemoved = true;
		}
		//Locked Functions
		SingletonHolder(void);
		SingletonHolder(const SingletonHolder&);
		SingletonHolder& operator=(const SingletonHolder&);
};//end of SingletonHolder class


#endif

